package com.pauldada.sakurabbs.dao;

import com.pauldada.sakurabbs.entities.Film;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

//帖子Repository接口
public interface FilmRepository extends JpaRepository<Film, Integer>,JpaSpecificationExecutor<Film>{

	//随机获取n个帖子
	@Query(value="select * from t_film order by RAND() limit ?1",nativeQuery = true)
    List<Film> randomList(Integer n);

	//获取上一个帖子
	@Query(value="select * from t_film where id<?1 order by id desc limit 1",nativeQuery = true)
    Film getLast(Integer id);

	//获取下一个帖子
	@Query(value="select * from t_film where id>?1 order by id asc limit 1",nativeQuery = true)
    Film getNext(Integer id);

}
